<?php // no direct access
defined('_JEXEC') or die('Restricted access');
$user = &JFactory::getUser();
//var_dump($this->user);

$db = &JFactory::GetDBO();
$query = "SELECT e.* FROM #__users AS u LEFT JOIN #__users_extension AS e ON u.id=e.id WHERE e.id=$user->id";
$db->setQuery($query);
$row = $db->loadObject();
//var_dump($row);
 ?>

<script type="text/javascript">
<!--
	Window.onDomReady(function(){
		document.formvalidator.setHandler('passverify', function (value) { return ($('password').value == value); }	);
	});
// -->
</script>

<script type="text/javascript">
$(document).ready(function(){	
     reset_update=function(){
     //e.preventDefault(); 
	 //alert("aaaaaaa");
     $("#email").attr("value","");
     $("#name").attr("value","");
     $("#address").attr("value","");
     $("#firma").attr("value","");
	 $("#postnr").attr("value","");
	 $("#mobile").attr("value","");
	 $("#by").attr("value","");
	 $("#phonetable").attr("value","");
	 $("#password").attr("value","");
	 $("#password2").attr("value","");
     return false;
	 };
    });
</script>
<script type="text/javascript">
	$(document).ready(function(){
	
    update_profile=function(){
        
        if(($('#firma').attr("value") == "" )){
            $('#alert').html('Udfyld venligst Firma');
            $('#backoverlay').show();
            $('#show_popup').show();
            $('#f_focus').html('firma');
            return false;	
        }
		
		if(($('#name').attr("value") == "" )){
            $('#alert').html('Udfyld venligst Kontaktperson');
            $('#backoverlay').show();
            $('#show_popup').show();
            $('#f_focus').html('name');
            return false;	
        }
		
		if(($('#address').attr("value") == "" )){
            $('#alert').html('Udfyld venligst Address');
            $('#backoverlay').show();
            $('#show_popup').show();
            $('#f_focus').html('address');
            return false;	
        }
		
		if(($('#postnr').attr("value") == "" )){
            $('#alert').html('Udfyld venligst Postnr.');
            $('#backoverlay').show();
            $('#show_popup').show();
            $('#f_focus').html('postnr');
            return false;	
        }
		
		if(isNaN($('#postnr').val())){
			$('#alert').html('Postnr eneste tal');
            $('#backoverlay').show();
			$('#show_popup').show();
			$('#f_focus').html('postnr');
			return false;	     
        }
		
		if(($('#by').attr("value") == "" )){
            $('#alert').html('Udfyld venligst By');
            $('#backoverlay').show();
            $('#show_popup').show();
            $('#f_focus').html('by');
            return false;	
        }
		
		if(($('#phonetable').attr("value") == "" )){
            $('#alert').html('Udfyld venligst Tlf.nr.');
            $('#backoverlay').show();
            $('#show_popup').show();
            $('#f_focus').html('phonetable');
            return false;	
        }
			
		if(isNaN($('#phonetable').val())){
			$('#alert').html('Tlf.nr. eneste tal');
            $('#backoverlay').show();
			$('#show_popup').show();
			$('#f_focus').html('phonetable');
			return false;	     
        }
		
		
        
        if(($('#email').attr("value") == "" )){
		//alert("aaaa");
            $('#alert').html('Udfyld venligst Email');
            $('#backoverlay').show();
            $('#show_popup').show();
            $('#f_focus').html('email');
            return false;	
        }
        
        else{
            if(!isEmail($('#email').val())){
                $('#alert').html('Venligst e-mail er gyldig');
                $('#backoverlay').show();
                $('#show_popup').show();
                $('#s_focus').html('email');
                return false; 
            }
        }
             	
		
		
		/* if(($('#password').attr("value") == "" )){
            $('#alert').html('Udfyld venligst Adgangskode');
            $('#backoverlay').show();
            $('#show_popup').show();
            $('#f_focus').html('password');
            return false;	
        }
				
		if(($('#password2').attr("value") == "" )){
            $('#alert').html('Udfyld venligst Bekræft adgangskode');
            $('#backoverlay').show();
            $('#show_popup').show();
            $('#f_focus').html('password2');
            return false;	
        }*/
		
		if($('#password').val()!=$('#password2').val()){
           $('#alert').html('Udfyld venligst Adgangskode');
            $('#backoverlay').show();
			$('#show_popup').show();
			$('#f_focus').html('password2');
			return false;
        }  
		
        $('#update_profile').click();
        
        return true;
	};    
     isEmail=function(string) {
		if (string.search(/^\w+((-\w+)|(\.\w+)|(\_\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
			return true;
		else return false;
    };
    close_popup=function(){		
		var fel=$('#f_focus').html();
        $('#backoverlay').hide();
		$('#show_popup').hide();
		$('#' + fel ).focus();
	};
    
    });

</script>
<div id="main">
<div id="content">
<nav id="bestilNav">
	<ul>
		<li><a href="index.php?option=com_ecommerce&view=list&Itemid=24"><span class="title">BESTIL Rengøring</span><span class="note">Se vores udvalg af tjenester</span></a></li>
		<li><a href="index.php?option=com_ecommerce&view=orders&Itemid=24"><span class="title">MINE BESTILINGER</span><span class="note">Hvad har jeg tidligere bestilt</span></a></li>
		<li class="active"><a href="index.php?option=com_user&view=user&layout=myprofile"><span class="title">Min profil</span><span class="note">se og redigere min profil</span></a></li>
	</ul>
	{module minicart}
	
</nav>
<!-- Begin corporate structure  -->
<div class="content-ctn">
	<div id="accountContent">
		<form action="<?php echo JRoute::_( 'index.php' ); ?>" method="post" name="userform" id="opretKontoForm" autocomplete="off">
			<fieldset>
				<!--Kunde infomation-->
				<div class="client-info block-decor fl-left">
					<div class="form-set-ctn">
						<h2>Konto infomation</h2>
						<div class="input-set">
						<?php 
						//echo $this->escape($this->user->get( 'name' ));
						?>
									<label>Firma <span>*</span></label>
									<input type="text" value="<?php echo $row->company ?>" name="firma" id="firma" class="input-txt">
									<label id="namemsg" for="name">Kontaktperson <span>*</span></label>
									<input type="text" name="name" id="name" size="40" value="<?php echo $this->escape($this->user->get( 'name' ));?>" class="input-txt" maxlength="50" />
									<label>Adresse <span>*</span></label>
									<input type="text" value="<?php echo $row->address ?>" name="address" id="address" class="input-txt">
									<label>Postnr. <span>*</span></label>
									<input type="text" value="<?php echo $row->post ?>" name="postnr" id="postnr" class="input-txt post-num">
									<label class="city">By <span>*</span></label>
									<input type="text" value="<?php echo $row->city ?>" name="by" id="by" class="city">
									<label>Tlf.nr. <span>*</span></label>
									<input type="text" value="<?php echo $row->phonetable ?>" name="phonetable" id="phonetable" class="input-txt">
									<label>Mobil.nr.</label>
									<input type="text" value="<?php echo $row->mobil ?>" name="mobil" id="mobil" class="input-txt">
									<label id="emailmsg" for="email">Email <span>*</span></label>
									<input type="text" id="email" name="email" size="40" value="<?php echo $this->escape($this->user->get( 'email' ));?>" class="input-txt">
									<label id="VRnr" for="VRnr">CVR-nr.</label>
									<input type="text" value="<?php echo $row->VRnr ?>" name="VRnr" id="VRnr" class="input-txt">
									<label id="usernamemsg" for="username">Brugernavn <span>*</span></label>
									<input readonly="true" type="text" id="username" name="username" size="40" value="<?php echo $this->escape($this->user->get( 'username' ));?>" class="input-txt" maxlength="25" />
									<?php if($this->user->get('password')) : ?>
									<label id="pwmsg" for="password">Adgangskode <span>*</span></label>
									<input class="input-txt" type="password" id="password" name="password"  value="" />
									<label id="pw2msg" for="password2">Bekræft adgangskode <span>*</span></label>
									<input class="input-txt" type="password" id="password2" name="password2" value="" /> 
									<?php endif; ?>
									<p class="note fl-right">Elter markeret med <span>*</span> skal udfyldes</p>
							
						</div>
					</div>
				</div>
									<div class="form-submit">
										<a href="javascript:void(0);" onclick="update_profile();" class="update-btn fl-left">Send</a>
										<a href="javascript:void(0);" onclick="reset_update();" class="cancel-btn fl-left">Nustil</a>
									</div>
			</fieldset>
									<?php if(isset($this->params)) :  echo $this->params->render( 'params' ); endif; ?>
									<button class="button validate" id="update_profile" name="update_profile" type="submit" style="display:none" ><?php echo JText::_('Save'); ?></button>									
									<input type="hidden" name="id" value="<?php echo $this->user->get('id');?>" />
									<input type="hidden" name="gid" value="<?php echo $this->user->get('gid');?>" />
									<input type="hidden" name="option" value="com_user" />
									<input type="hidden" name="task" value="save" />
	<?php echo JHTML::_( 'form.token' ); ?>
		</form>
	</div>
</div>
<!-- / corporate structure  -->

</div>
</div>

